// 2025/3/7
// https://leetcode.cn/problems/search-a-2d-matrix-ii/description/?envType=study-plan-v2&envId=top-100-liked
// 搜索二维矩阵2

class Solution {
    public:
        bool searchMatrix(vector<vector<int>>& matrix, int target) {
            int m = matrix.size(), n = matrix[0].size();
            int x = m - 1, y = 0;
            while(x >= 0 && y < n)
            {
                if(matrix[x][y] > target)
                    --x;
                else if(matrix[x][y] < target)
                    ++y;
                else
                    return true;
            }
    
            return false;
        }
    };